package br.com.tccallan.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.faces.context.FacesContext;

import br.com.tccallan.dao.DAO;
import br.com.tccallan.entity.Termo;

public class TermoController {
	
	private Termo termo;
	private List<Termo> termoList;

	public TermoController() {
	}
	public Termo getTermo() {
		return termo;
	}


	public void setTermo(Termo termo) {
		this.termo = termo;
	}

	public List<Termo> getTermoList() {
		return termoList;
	}
	public void setTermoList(List<Termo> termoList) {
		this.termoList = termoList;
	}
	public void cadastrarTermo() throws Exception {
		try {
			termo = new Termo();
			FacesContext.getCurrentInstance().getExternalContext()
					.redirect("cadastrarTermo.jsp");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void salvar() throws Exception {
		DAO.getInstance().saveOrUpdate(termo);
		termo = new Termo();
	}


	public void carregar() throws IOException {
		FacesContext context = FacesContext.getCurrentInstance();
		termo = (Termo) context.getExternalContext().getRequestMap()
				.get("list");
		FacesContext.getCurrentInstance().getExternalContext()
				.redirect("cadastrarTermo.jsp");
	}

	@SuppressWarnings("unchecked")
	public List<Termo> listarTermo() {
		try {
			termoList = new ArrayList<Termo>();
			termoList = DAO.getInstance().list(Termo.class, "dataIni");
			FacesContext.getCurrentInstance().getExternalContext()
					.redirect("listarTermo.jsp");
		} catch (IOException e) {
			e.printStackTrace();
		}
		return termoList;
	}

	
}
